package cn.edu.neusoft.neufooddemo.activity;

import android.view.View;
import android.widget.ImageView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.edu.neusoft.neufooddemo.R;
import cn.edu.neusoft.neufooddemo.adapter.CommentAdapter;
import cn.edu.neusoft.neufooddemo.bean.CommentInfo;
import cn.edu.neusoft.neufooddemo.listener.RetrofitListener;
import cn.edu.neusoft.neufooddemo.model.FoodModel;

public class MyCommentActivity extends BaseActivity implements RetrofitListener<List<CommentInfo>>{

    private RecyclerView mycomment_rv;
    private ImageView mycomment_return;
    private CommentAdapter adapter;
    private FoodModel foodModel;

    protected void initViews(){
        setLayout(R.layout.activity_mycomment);
        mycomment_rv = (RecyclerView) findViewById(R.id.mycomment_rv);
        mycomment_rv.setLayoutManager(new LinearLayoutManager(MyCommentActivity.this));
        mycomment_return = (ImageView)findViewById(R.id.mycomment_return);
    }

    void initEvents(){
        mycomment_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

     void initData(){
        foodModel=new FoodModel();
        foodModel.getAllUserComment(getUser_id(),this);
    }

    @Override
    public void onSuccess(List<CommentInfo> commentInfos, int flag) {
        adapter = new CommentAdapter(MyCommentActivity.this, commentInfos, R.layout.cardview_comment);
        mycomment_rv.setAdapter(adapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }

    @Override
    public void onFail() {
        showToast("网络错误");
    }
}
